<template>
  <el-dialog :title="formData.id?'编辑':'添加'" :visible.sync="modelShow">
    <el-form ref="modelForm" :model="formData" label-width="120px" :rules="formRules">
      <el-form-item label="数据源ID">
        <el-input :disabled="isDatasourceId"  v-model="formData.datasourceId" placeholder="请输入数据源"/>
      </el-form-item>
      <el-form-item label="API名称">
        <el-input v-model="formData.resourceName" placeholder="请输入API名称"/>
      </el-form-item>
      <el-form-item label="API编码">
         <el-input v-model="formData.apiCode" placeholder="请输入API"/>
      </el-form-item>
      <el-form-item label="SQL表达式">
        <el-input v-model="formData.apiDefination" placeholder="请输入SQL表达式"/>
      </el-form-item>
      <el-form-item>
        <el-button @click="modelShow = false">取 消</el-button>
        <el-button type="primary" @click="submitForm()">确 定</el-button>
      </el-form-item>
    </el-form>
  </el-dialog>
</template>

<script>
import {saveOrUpdateApi} from "@/api/DataApi";
import {fileUrl} from "/env";
import {getToken} from "@/utils/auth";

export default {
  name: "ImgPoolForm",
  data() {
    return {
      uploadHeaders:{'X-Token':getToken()},
      fileUrl:fileUrl,
      fileId:'',
      isDatasourceId:false,
      formData:{},
      modelShow:false,
      formRules:{
        groupId: [
          { required: true, message: '请选择分组', trigger: 'blur' }
        ]
      },
      groups:[]
    }
  },
  methods:{
    opened(isEdit,row){
      this.formData = {};
      this.fileId = '';
      if (isEdit){
        this.formData = row;
        this.fileId = this.formData.fileId
        this.isDatasourceId  = true;
      }else{this.isDatasourceId  = false;}
      this.modelShow = true;
    },
    submitForm(){
		debugger
      saveOrUpdateApi(this.formData).then(() => {
        this.modelShow = false
        this.$emit('refreshTable');
     })
    },
    handleAvatarSuccess(res,file) {
      if (res.code !== 1){
        this.$message.error(res.msg)
      }
      this.fileId = res.data;
      this.formData.imgName = file.name.substr(0,file.name.lastIndexOf('.'));
    }
  
  }
}
</script>

<style scoped>

</style>
